﻿Option Strict On

Imports System.ComponentModel
Imports System.Drawing
Imports System.Runtime.CompilerServices
Imports System.Runtime.InteropServices

<EditorBrowsable(EditorBrowsableState.Advanced)>
Public Module Extensions

    <EditorBrowsable(EditorBrowsableState.Advanced)>
    <Extension()>
    Public Function Center(rect As Rectangle) As Point
        Return New Point(rect.X + CInt(rect.Width / 2), rect.Y + CInt(rect.Height / 2))
    End Function

    <EditorBrowsable(EditorBrowsableState.Advanced)>
    <Extension()>
    Public Function Center(rect As RectangleF) As PointF
        Return New PointF(rect.X + rect.Width / 2, rect.Y + rect.Height / 2)
    End Function

    <EditorBrowsable(EditorBrowsableState.Advanced)>
    <Extension()>
    Public Function Contains(source As IEnumerable(Of PointF), targetLocation As PointF) As Boolean
        Return Geometry.PolygonContains(targetLocation, source.ToArray)
    End Function

    <EditorBrowsable(EditorBrowsableState.Advanced)>
    <Extension()>
    Public Function Contains(source As IEnumerable(Of Vector2), targetLocation As Vector2) As Boolean
        Return Geometry.PolygonContains(targetLocation, source.ToArray)
    End Function

    <EditorBrowsable(EditorBrowsableState.Advanced)>
    <Extension()>
    Public Function DistanceTo(source As System.Drawing.Point, target As System.Drawing.Point) As Double
        Return CDbl(Vector2.GetDistance(New Vector2(source), New Vector2(target)))
    End Function

    <EditorBrowsable(EditorBrowsableState.Advanced)>
    <Extension()>
    Public Function DistanceTo(source As System.Drawing.PointF, target As System.Drawing.PointF) As Double
        Return CDbl(Vector2.GetDistance(New Vector2(source), New Vector2(target)))
    End Function

    <EditorBrowsable(EditorBrowsableState.Advanced)>
    <Extension()>
    Public Function InRangeOf(source As Integer, target As Integer, range As Integer) As Boolean
        Return Geometry.InRangeOf(source, target, range)
    End Function

    <EditorBrowsable(EditorBrowsableState.Advanced)>
    <Extension()>
    Public Function InRangeOf(source As Single, target As Single, range As Single) As Boolean
        Return Geometry.InRangeOf(source, target, range)
    End Function

    <EditorBrowsable(EditorBrowsableState.Advanced)>
    <Extension()>
    Public Function InRangeOf(source As Double, target As Double, range As Double) As Boolean
        Return Geometry.InRangeOf(source, target, range)
    End Function

    <EditorBrowsable(EditorBrowsableState.Advanced)>
    <Extension()>
    Public Function InRangeOf(source As Decimal, target As Decimal, range As Decimal) As Boolean
        Return Geometry.InRangeOf(source, target, range)
    End Function
End Module